﻿Imports 坐标转换类
Imports 坐标转换类.CoordTrans

Public Class Form1
    'Dim CT As New CoordTrans

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        grd.Rows.Add(2)
        grd.Rows(0).Cells(0).Value = 474.85
        grd.Rows(0).Cells(1).Value = -573.75
        grd.Rows(0).Cells(2).Value = 79.06
        grd.Rows(0).Cells(3).Value = -971.59
        grd.Rows(1).Cells(0).Value = 249.968
        grd.Rows(1).Cells(1).Value = -459.984
        grd.Rows(1).Cells(2).Value = -6.71
        grd.Rows(1).Cells(3).Value = -667.48

        grd2.Rows.Add(1)

    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim mark1, mark2 As PointF
        Dim ptCenter As PointF          '相机2的旋转中心点
        Dim Cam1_P1, Cam1_P2 As PointF  '相机1 Mark点
        Dim Cam2_P1, Cam2_P2 As PointF  '相机2 Mark点
        Dim Cam1_Center As PointF       '相机1　Mark点的中心点
        Dim Cam2_Center As PointF       '相机2　Mark点的中心点


        Dim ptResult As PointF
        Dim angleResult As Single

        Dim angle_Cam1_Default As Single
        Dim angle_Cam2_Default As Single
        Dim angle_Cam1 As Single
        Dim angle_Cam2 As Single


        mark1.X = Mark1_X.Value
        mark1.Y = Mark1_Y.Value
        mark2.X = Mark2_X.Value
        mark2.Y = Mark2_Y.Value

        Cam1_P1.X = grd.Rows(0).Cells(0).Value
        Cam1_P1.Y = grd.Rows(0).Cells(1).Value
        Cam1_P2.X = grd.Rows(0).Cells(2).Value
        Cam1_P2.Y = grd.Rows(0).Cells(3).Value

        Cam2_P1.X = grd.Rows(1).Cells(0).Value
        Cam2_P1.Y = grd.Rows(1).Cells(1).Value
        Cam2_P2.X = grd.Rows(1).Cells(2).Value
        Cam2_P2.Y = grd.Rows(1).Cells(3).Value

        ptCenter.X = Cam2_Center_X.Value
        ptCenter.Y = Cam2_Center_Y.Value

        Cam1_Center = CenterOfTwoPoint(Cam1_P1, Cam1_P2)
        Cam2_Center = CenterOfTwoPoint(Cam2_P1, Cam2_P2)

        angle_Cam1_Default = get_point_angle(mark1, mark2)
        angle_Cam2_Default = angle_Cam1_Default
        angle_Cam1 = get_point_angle(Cam1_P1, Cam1_P2)
        angle_Cam2 = get_point_angle(Cam2_P1, Cam2_P2)

        angleResult = (angle_Cam1 - angle_Cam1_Default) - (angle_Cam2 - angle_Cam2_Default)

        Dim pt1 As PointF
        pt1 = P_Rotate(Cam2_Center, ptCenter, angleResult)
        ptResult = PointSub(pt1, Cam1_Center)


        grd2.Rows(0).Cells(0).Value = ptResult.X
        grd2.Rows(0).Cells(1).Value = ptResult.Y
        grd2.Rows(0).Cells(2).Value = angleResult


    End Sub


    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
        Dim pt1 As PointF
        Dim mark1, mark2 As PointF
        Dim angel As Single
        angel = grd.Rows(0).Cells(0).Value

        mark1.X = Mark1_X.Value
        mark1.Y = Mark1_Y.Value
        mark2.X = Mark2_X.Value
        mark2.Y = Mark2_Y.Value
        pt1 = P_Rotate(mark1, mark2, angel)

        grd2.Rows(0).Cells(0).Value = pt1.X
        grd2.Rows(0).Cells(1).Value = pt1.Y
    End Sub
End Class
